﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SJ.Platform.Common;
using SJ.Platform.EFCore.Common;
using SJ.Platform.EFCore.DBOperation.DBOperation.MySQL.Project;
using SJ.Platform.EFCore.Model;
using SJ.Platform.EFCore.Model.ProjectManager;
using SJ.Platform.Extend.IOC.CurrentUser;
using SJ.Platform.Extend.ModelExtend;
using SJ.Platform.Extend.ModelExtend.ProjectExt;
using SJ.Platform.Extend.Request;
using SJ.Platform.Extend.Response;

namespace SJ.Platform.Api.Controllers.ProjectManager
{
    /// <summary>
    /// 项目进度计划操作类
    /// </summary>
    [Route(GlobalVariableHandle.Scope_Api + "/ProjectSchedule")]
    [ApiController]
    [Authorize(GlobalVariableHandle.Scope_Api)]
    public class ProjectScheduleController : ControllerBase
    {
        private readonly SJDBContext _context;
        private readonly ICurrentUser _currentUser;
        private readonly Project_Schedule_MainHandle _mainHandle;
        private readonly Project_Schedule_TaskHandle _taskHandle;
        private readonly Project_Schedule_Task_DoHandle _taskDoHandle;
        private readonly Project_Schedule_PersonHandle _personHandle;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="dbContext">数据库</param>
        /// <param name="currentUser">当前用户</param>
        public ProjectScheduleController(SJDBContext dbContext, ICurrentUser currentUser)
        {
            _context = dbContext;
            _currentUser = currentUser;
            _mainHandle = new Project_Schedule_MainHandle(dbContext);
            _taskHandle = new Project_Schedule_TaskHandle(dbContext);
            _taskDoHandle = new Project_Schedule_Task_DoHandle(dbContext);
            _personHandle = new Project_Schedule_PersonHandle(dbContext);
        }

        /// <summary>
        /// 编制进度计划
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost("FormulateProjectScheduleAsync")]
        public async Task<IActionResult> FormulateProjectScheduleAsync([FromBody] ProjectScheduleMainExtend model)
        {
            try
            {
                bool result = await TransactionHandle.ExecuteInTransactionAsync<bool>(_context, async () =>
                {
                    //先清空之前的记录
                    bool actionResult = await _mainHandle.DeleteByProjectIdAsync(model.ProjectId) && await _taskHandle.DeleteByProjectIdAsync(model.ProjectId) && await _personHandle.DeleteByProjectIdAsync(model.ProjectId);

                    //主记录
                    ProjectScheduleMain scheduleMain = model.ExtMapToEntity<ProjectScheduleMain, ProjectScheduleMainExtend>();
                    scheduleMain.Status = 1;
                    scheduleMain.AddTime = scheduleMain.AddTime == null ? DateTime.Now : scheduleMain.AddTime;
                    scheduleMain.AddUserId = string.IsNullOrWhiteSpace(scheduleMain.AddUserId) ? _currentUser.UserId : scheduleMain.AddUserId;
                    scheduleMain.EditUserId = _currentUser.UserId;
                    scheduleMain.EditTime = DateTime.Now;

                    List<ProjectScheduleTask> taskList = new List<ProjectScheduleTask>();
                    List<ProjectSchedulePerson> personList = new List<ProjectSchedulePerson>();
                    DealSchedule(scheduleMain, model.Tasks, taskList, personList);

                    //保存新的记录
                    actionResult = await _mainHandle.CreateAsync(scheduleMain);
                    if (taskList.Count > 0 && actionResult)
                    {
                        actionResult = await _taskHandle.BatchCreateAsync(taskList);
                    }
                    if (personList.Count > 0 && actionResult)
                    {
                        actionResult = await _personHandle.BatchCreateAsync(personList);
                    }
                    return actionResult;
                });

                return Ok(ApiNormalResponse<bool>.SetResponse(result ? ApiResponseStatus.Success : ApiResponseStatus.BadRequest, "项目进度计划添加" + (result ? "成功" : "失败"), result));
            }
            catch (Exception ex)
            {
                // 处理异常情况
                return BadRequest(ApiNormalResponse<bool>.SetResponse(ApiResponseStatus.BadRequest, "项目进度计划添加失败：" + ex.Message, false));
            }
        }

        /// <summary>
        /// 更新项目进度计划指定的内容
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost("UpdateScheduleMainSpecificContentAsync")]
        public async Task<IActionResult> UpdateScheduleMainSpecificContentAsync([FromBody] ProjectScheduleMainExtend model)
        {
            try
            {
                //默认更新最后修改时间和修改人
                model.EditTime = DateTime.Now;
                model.EditUserId = _currentUser.UserId;
                model.UpdateProperties.Add("EditTime");
                model.UpdateProperties.Add("EditUserId");
                bool result = await _mainHandle.UpdateScheduleMainSpecificContentAsync(model);
                return Ok(ApiNormalResponse<bool>.SetResponse(result ? ApiResponseStatus.Success : ApiResponseStatus.BadRequest, "项目更新" + (result ? "成功" : "失败"), result));
            }
            catch (Exception ex)
            {
                // 处理异常情况
                return BadRequest(ApiNormalResponse<bool>.SetResponse(ApiResponseStatus.BadRequest, "项目更新失败：" + ex.Message, false));
            }
        }

        /// <summary>
        /// 处理进度计划中的功能和负责人
        /// </summary>
        /// <param name="list"></param>
        /// <param name="taskList"></param>
        /// <param name="personList"></param>
        private void DealSchedule(ProjectScheduleMain scheduleMain, List<ProjectScheduleTaskExtend> list, List<ProjectScheduleTask> taskList, List<ProjectSchedulePerson> personList)
        {
            try
            {
                foreach (ProjectScheduleTaskExtend item in list)
                {
                    ProjectScheduleTask task = item.ExtMapToEntity<ProjectScheduleTask, ProjectScheduleTaskExtend>();
                    task.AddTime = scheduleMain.AddTime;
                    task.AddUserId = scheduleMain.AddUserId;
                    task.EditUserId = scheduleMain.EditUserId;
                    task.EditTime = scheduleMain.EditTime;
                    taskList.Add(task);

                    if (item.Persons != null && item.Persons.Count > 0)
                    {
                        foreach (ProjectSchedulePerson person in item.Persons)
                        {
                            person.Id = Guid.NewGuid().ToString();
                            person.MId = task.Mid;
                            person.TaskId = task.Id;
                            person.ProjectId = task.ProjectId;
                            personList.Add(person);
                        }
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }

        /// <summary>
        /// 根据进度ID获取进度详情
        /// </summary>
        /// <param name="scheduleId"></param>
        /// <returns></returns>
        [HttpGet("GetScheduleDetailByScheduleIdAsync/{scheduleId}")]
        public async Task<IActionResult> GetScheduleDetailByScheduleIdAsync(string scheduleId)
        {
            try
            {
                var result = await _taskHandle.GetSchedulesByScheduleIdAsync(scheduleId);               
                return Ok(ApiNormalResponse<List<ProjectScheduleTaskExtend>>.SetResponse(ApiResponseStatus.Success, "查询成功", result)); // 返回成功的响应
            }
            catch (Exception ex)
            {
                // 处理异常情况
                return BadRequest(ApiNormalResponse<List<ProjectScheduleTaskExtend>>.SetResponse(ApiResponseStatus.BadRequest, "查询失败：" + ex.Message, new List<ProjectScheduleTaskExtend> { }));
            }
        }

        /// <summary>
        /// 根据项目ID获取项目进度计划
        /// </summary>
        /// <param name="projectId"></param>
        /// <returns></returns>
        [HttpGet("GetScheduleDetailByProjectIdAsync/{projectId}")]
        public async Task<IActionResult> GetScheduleDetailByProjectIdAsync(string projectId)
        {
            try
            {
                ProjectScheduleMainExtend mainExtend = await _mainHandle.GetEntityByProjectIdAsync(projectId);
                if (mainExtend.Tasks == null)
                {
                    mainExtend.Tasks = new List<ProjectScheduleTaskExtend>();
                }
                mainExtend.Tasks = await _taskHandle.GetSchedulesByProjectIdAsync(projectId);
                return Ok(ApiNormalResponse<ProjectScheduleMainExtend>.SetResponse(ApiResponseStatus.Success, "查询成功", mainExtend)); // 返回成功的响应
            }
            catch (Exception ex)
            {
                // 处理异常情况
                return BadRequest(ApiNormalResponse<ProjectScheduleMainExtend>.SetResponse(ApiResponseStatus.BadRequest, "查询失败：" + ex.Message, new ProjectScheduleMainExtend { }));
            }
        }

        /// <summary>
        /// 根据项目ID获取项目进度计划基本信息
        /// </summary>
        /// <param name="projectId"></param>
        /// <returns></returns>
        [HttpGet("GetScheduleEntityByProjectIdAsync/{projectId}")]
        public async Task<IActionResult> GetScheduleEntityByProjectIdAsync(string projectId)
        {
            try
            {
                ProjectScheduleMainExtend mainExtend = await _mainHandle.GetEntityByProjectIdAsync(projectId);               
                return Ok(ApiNormalResponse<ProjectScheduleMainExtend>.SetResponse(ApiResponseStatus.Success, "查询成功", mainExtend)); // 返回成功的响应
            }
            catch (Exception ex)
            {
                // 处理异常情况
                return BadRequest(ApiNormalResponse<ProjectScheduleMainExtend>.SetResponse(ApiResponseStatus.BadRequest, "查询失败：" + ex.Message, new ProjectScheduleMainExtend { }));
            }
        }

        /// <summary>
        /// 根据项目ID获取项目进度计划树
        /// </summary>
        /// <param name="projectId"></param>
        /// <returns></returns>
        [HttpGet("GetProjectScheduleTreeAsync/{projectId}")]
        public async Task<IActionResult> GetProjectScheduleTreeAsync(string projectId)
        {
            try
            {
                var result = await _taskHandle.GetProjectScheduleTreeByProjectIdAsync(projectId);
                return Ok(ApiNormalResponse<List<ProjectScheduleTaskExtend>>.SetResponse(ApiResponseStatus.Success, "查询成功", result)); // 返回成功的响应
            }
            catch (Exception ex)
            {
                // 处理异常情况
                return BadRequest(ApiNormalResponse<List<ProjectScheduleTaskExtend>>.SetResponse(ApiResponseStatus.BadRequest, "查询失败：" + ex.Message, new List<ProjectScheduleTaskExtend> { }));
            }
        }

        /// <summary>
        /// 根据ID获取进度计划信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("GetScheduleDetailByIdAsync/{id}")]
        public async Task<IActionResult> GetScheduleDetailByIdAsync(string id)
        {
            try
            {
                //进度计划主记录
                ProjectScheduleMainExtend mainExtend = await _mainHandle.GetEntityByIdAsync(id);
                //获取进度计划细则
                if (mainExtend.Tasks == null)
                {
                    mainExtend.Tasks = new List<ProjectScheduleTaskExtend>();
                }
                mainExtend.Tasks = await _taskHandle.GetSchedulesByProjectIdAsync(mainExtend.ProjectId);

                return Ok(ApiNormalResponse<ProjectScheduleMainExtend>.SetResponse(ApiResponseStatus.Success, "查询成功", mainExtend)); // 返回成功的响应
            }
            catch (Exception ex)
            {
                // 处理异常情况
                return BadRequest(ApiNormalResponse<ProjectScheduleMainExtend>.SetResponse(ApiResponseStatus.BadRequest, "查询失败：" + ex.Message, new ProjectScheduleMainExtend { }));
            }
        }

        /// <summary>
        /// 获取所有项目进度计划
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("GetProjectSchedulesAsync")]
        public async Task<IActionResult> GetProjectSchedulesAsync([FromBody] ApiPageQueryRequest<ProjectScheduleMainExtend> request)
        {
            try
            {
                var result = await _mainHandle.GetProjectSchedulesAsync((int)request.PageIndex, (int)request.PageSize, _currentUser.UserId, ApiPageQueryRequest<ProjectScheduleMainExtend>.GenerateCondition(request.Condition));

                return Ok(ApiPageQueryResponse<List<ProjectScheduleMainExtend>>.SetResponse(ApiResponseStatus.Success, "查询成功", (int)request.PageIndex, (int)request.PageSize, result.count, result.mainExtends)); // 返回成功的响应
            }
            catch (Exception ex)
            {
                // 处理异常情况
                return BadRequest(ApiPageQueryResponse<List<ProjectScheduleMainExtend>>.SetResponse(ApiResponseStatus.BadRequest, "查询失败：" + ex.Message, (int)request.PageIndex, (int)request.PageSize, 0, new List<ProjectScheduleMainExtend> { }));
            }
        }

        /// <summary>
        /// 根据需求ID获取进度任务
        /// </summary>
        /// <param name="rId"></param>
        /// <returns></returns>
        [HttpGet("GetScheduleTaskByRIdAsync/{rId}")]
        public async Task<IActionResult> GetScheduleTaskByRIdAsync(string rId)
        {
            try
            {
                var result = await _taskHandle.GetEntityByRIdAsync(rId);

                return Ok(ApiNormalResponse<ProjectScheduleTask>.SetResponse(ApiResponseStatus.Success, "查询成功", result)); // 返回成功的响应
            }
            catch (Exception ex)
            {
                // 处理异常情况
                return BadRequest(ApiNormalResponse<ProjectScheduleTask>.SetResponse(ApiResponseStatus.BadRequest, "查询失败：" + ex.Message, new ProjectScheduleTask { }));
            }
        }

        /// <summary>
        /// 根据负责人获取任务列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("GetTasksOfPersonAsync")]
        public async Task<IActionResult> GetTasksOfPersonAsync([FromBody] ApiPageQueryRequest<ProjectScheduleTask> request)
        {
            try
            {
                var result = await _taskHandle.GetProjectScheduleTasksAsync((int)request.PageIndex, (int)request.PageSize, _currentUser.UserId, ApiPageQueryRequest<ProjectScheduleTask>.GenerateCondition(request.Condition));
                return Ok(ApiPageQueryResponse<List<ProjectScheduleTask>>.SetResponse(ApiResponseStatus.Success, "查询成功", (int)request.PageIndex, (int)request.PageSize, result.count, result.tasks)); // 返回成功的响应
            }
            catch (Exception ex)
            {
                // 处理异常情况
                return BadRequest(ApiPageQueryResponse<List<ProjectScheduleTask>>.SetResponse(ApiResponseStatus.BadRequest, "查询失败：" + ex.Message, (int)request.PageIndex, (int)request.PageSize, 0, new List<ProjectScheduleTask> { }));
            }
        }

        /// <summary>
        /// 根据任务ID获取完成记录
        /// </summary>
        /// <param name="taskId"></param>
        /// <returns></returns>
        [HttpGet("GetTaskDosByTaskIdAsync/{taskId}")]
        public async Task<IActionResult> GetTaskDosByTaskIdAsync(string taskId)
        {
            try
            {
                var result = await _taskDoHandle.GetTaskDosByTaskIdAsync(taskId);
                return Ok(ApiNormalResponse<List<ProjectScheduleTaskDoExtend>>.SetResponse(ApiResponseStatus.Success, "查询成功", result)); // 返回成功的响应
            }
            catch (Exception ex)
            {
                // 处理异常情况
                return BadRequest(ApiNormalResponse<List<ProjectScheduleTaskDoExtend>>.SetResponse(ApiResponseStatus.BadRequest, "查询失败：" + ex.Message, new List<ProjectScheduleTaskDoExtend> { }));
            }
        }

        /// <summary>
        /// 根据任务ID递归获取该任务下所有子任务
        /// </summary>
        /// <param name="taskId"></param>
        /// <returns></returns>
        [HttpGet("GetDeepChildTasksByPIdAsync/{taskId}")]
        public async Task<IActionResult> GetDeepChildTasksByPIdAsync(string taskId)
        {
            try
            {
                var result = await _taskHandle.GetDeepChildTasksByPIdAsync(taskId);
                return Ok(ApiNormalResponse<List<ProjectScheduleTaskExtend>>.SetResponse(ApiResponseStatus.Success, "查询成功", result)); // 返回成功的响应
            }
            catch (Exception ex)
            {
                // 处理异常情况
                return BadRequest(ApiNormalResponse<List<ProjectScheduleTaskExtend>>.SetResponse(ApiResponseStatus.BadRequest, "查询失败：" + ex.Message, new List<ProjectScheduleTaskExtend> { }));
            }
        }

        /// <summary>
        /// 添加任务完成记录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost("CreateTaskDoAsync")]
        public async Task<IActionResult> CreateTaskDoAsync([FromBody] ProjectScheduleTaskDo model)
        {
            try
            {
                bool result = await TransactionHandle.ExecuteInTransactionAsync<bool>(_context, async () =>
                {
                    model.Id = Guid.NewGuid().ToString();
                    model.AddTime = DateTime.Now;
                    model.AddUserId = _currentUser.UserId;
                    model.EditUserId = _currentUser.UserId;
                    model.EditTime = DateTime.Now;

                    //添加完成记录
                    bool actionResult = await _taskDoHandle.CreateAsync(model);

                    //更新当前任务进度，同时向上递归更新父级任务的进度
                    List<ProjectScheduleTask> tasks = new List<ProjectScheduleTask>();
                    ProjectScheduleTask task = await _taskHandle.GetEntityByIdAsync(model.TaskId);
                    task.Progress = model.Progress;

                    //计算父级任务的进度
                    await CalculateTaskProgress(task, tasks);

                    //更新任务进度
                    actionResult = await _taskHandle.UpdateScheduleTaskProgressAsync(tasks);

                    //更新项目进度
                    ProjectScheduleMain scheduleMain = await _mainHandle.GetEntityByIdAsync(task.Mid);
                    await CalculateScheduleProgress(scheduleMain, tasks);
                    actionResult = await _mainHandle.UpdateScheduleProgressAsync(scheduleMain);

                    return actionResult;
                });

                return Ok(ApiNormalResponse<bool>.SetResponse(result ? ApiResponseStatus.Success : ApiResponseStatus.BadRequest, "任务完成记录添加" + (result ? "成功" : "失败"), result));
            }
            catch (Exception ex)
            {
                // 处理异常情况
                return BadRequest(ApiNormalResponse<bool>.SetResponse(ApiResponseStatus.BadRequest, "任务完成记录添加失败：" + ex.Message, false));
            }
        }

        /// <summary>
        /// 计算任务的父级任务进度
        /// </summary>
        /// <param name="task"></param>
        /// <param name="tasks"></param>
        /// <returns></returns>
        private async Task CalculateTaskProgress(ProjectScheduleTask task, List<ProjectScheduleTask> tasks)
        {
            tasks.Add(task);
            if (!string.IsNullOrWhiteSpace(task.PId))//有父任务则要计算父任务的进度
            {
                ProjectScheduleTask p = await _taskHandle.GetEntityByIdAsync(task.PId);
                List<ProjectScheduleTask> childTasks = await _taskHandle.GetFirstLevelChildTasksByPIdAsync(task.PId);
                if (childTasks.Count == 1)//子任务只有一个，则子任务进度即父任务进度
                {
                    p.Progress = task.Progress;
                }
                else if (childTasks.Count > 1)//子任务有多个
                {
                    //计算天数
                    int days = 0, day = 0;//天数变量
                    Dictionary<string, int> dayDic = new Dictionary<string, int>();
                    foreach (var ct in childTasks)
                    {
                        day = DateTimeHandle.CalculateBusinessDays((DateTime)ct.StartTime, (DateTime)ct.EndTime);
                        dayDic[ct.Id] = day;
                        days += day;
                    }

                    //计算进度
                    double progress = 0.0;//进度
                    foreach (var ct in childTasks)
                    {
                        //当前任务进度
                        if (ct.Id == task.Id)
                        {
                            progress += Convert.ToDouble(dayDic[ct.Id]) / Convert.ToDouble(days) * Convert.ToDouble(task.Progress);
                        }
                        else
                        {
                            progress += ct.Progress == null ? 0.0 : Convert.ToDouble(dayDic[ct.Id]) / Convert.ToDouble(days) * Convert.ToDouble(ct.Progress);
                        }
                    }
                    p.Progress = Convert.ToDecimal(progress);
                }
                await CalculateTaskProgress(p, tasks);
            }
        }

        /// <summary>
        /// 计算项目进度
        /// </summary>
        /// <param name="scheduleMain"></param>
        /// <param name="tasks"></param>
        /// <returns></returns>
        private async Task CalculateScheduleProgress(ProjectScheduleMain scheduleMain, List<ProjectScheduleTask> tasks)
        {
            List<ProjectScheduleTask> childTasks = await _taskHandle.GetChildTasksByMIdAsync(scheduleMain.Id);
            if (childTasks.Count == 1)//子任务只有一个，则子任务进度即父任务进度
            {
                scheduleMain.Progress = tasks.Where(t => t.Id == childTasks[0].Id).First().Progress;
            }
            else if (childTasks.Count > 1)//子任务有多个
            {
                //计算天数
                int days = 0, day = 0;//天数变量
                Dictionary<string, int> dayDic = new Dictionary<string, int>();
                foreach (var ct in childTasks)
                {
                    day = DateTimeHandle.CalculateBusinessDays((DateTime)ct.StartTime, (DateTime)ct.EndTime);
                    dayDic[ct.Id] = day;
                    days += day;
                }

                //计算进度
                double progress = 0.0;//进度
                foreach (var ct in childTasks)
                {
                    //当前任务进度
                    if (tasks.Where(t => t.Id == ct.Id).Count() > 0)
                    {
                        progress += Convert.ToDouble(dayDic[ct.Id]) / Convert.ToDouble(days) * Convert.ToDouble(tasks.Where(t => t.Id == childTasks[0].Id).First().Progress);
                    }
                    else
                    {
                        progress += ct.Progress == null ? 0.0 : Convert.ToDouble(dayDic[ct.Id]) / Convert.ToDouble(days) * Convert.ToDouble(ct.Progress);
                    }
                }
                scheduleMain.Progress = Convert.ToDecimal(progress);
            }
        }

        /// <summary>
        /// 更新任务完成记录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost("UpdateTaskDoAsync")]
        public async Task<IActionResult> UpdateTaskDoAsync([FromBody] ProjectScheduleTaskDo model)
        {
            try
            {
                bool result = await TransactionHandle.ExecuteInTransactionAsync<bool>(_context, async () =>
                {
                    model.EditUserId = _currentUser.UserId;
                    model.EditTime = DateTime.Now;

                    //添加记录
                    bool actionResult = await _taskDoHandle.UpdateAsync(model);
                    return actionResult;
                });

                return Ok(ApiNormalResponse<bool>.SetResponse(result ? ApiResponseStatus.Success : ApiResponseStatus.BadRequest, "任务完成记录更新" + (result ? "成功" : "失败"), result));
            }
            catch (Exception ex)
            {
                // 处理异常情况
                return BadRequest(ApiNormalResponse<bool>.SetResponse(ApiResponseStatus.BadRequest, "任务完成记录更新失败：" + ex.Message, false));
            }
        }

        /// <summary>
        /// 根据ID删除任务完成记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("DelTaskDoByIdAsync/{id}")]
        public async Task<IActionResult> DelTaskDoByIdAsync(string id)
        {
            try
            {
                bool result = await TransactionHandle.ExecuteInTransactionAsync<bool>(_context, async () =>
                {
                    //添加记录
                    bool actionResult = await _taskDoHandle.DeleteByIdAsync(id);
                    return actionResult;
                });

                return Ok(ApiNormalResponse<bool>.SetResponse(result ? ApiResponseStatus.Success : ApiResponseStatus.BadRequest, "任务完成记录删除" + (result ? "成功" : "失败"), result)); // 返回成功的响应
            }
            catch (Exception ex)
            {
                // 处理异常情况
                return BadRequest(ApiNormalResponse<bool>.SetResponse(ApiResponseStatus.BadRequest, "任务完成记录删除失败：" + ex.Message, false));
            }
        }
    }
}
